

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=auto>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/fluid.png">
  <link rel="icon" href="/img/fluid.png">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="author" content="深海火锅店">
  <meta name="keywords" content="">
  
    <meta name="description" content="Vue3学习 要求，点击按钮，改变数据vue2的写法也可以实现  1234567891011121314151617181920212223242526272829303132333435&lt;template&gt;  &lt;div class&#x3D;&quot;home&quot;&gt;    &lt;button @click&#x3D;&quot;test&quot;&gt;点击&lt;&#x2F;butto">
<meta property="og:type" content="article">
<meta property="og:title" content="Vue3学习">
<meta property="og:url" content="http://example.com/2023/04/16/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/Vue/Vue3/Vue3%E5%AD%A6%E4%B9%A0/index.html">
<meta property="og:site_name" content="Hexo">
<meta property="og:description" content="Vue3学习 要求，点击按钮，改变数据vue2的写法也可以实现  1234567891011121314151617181920212223242526272829303132333435&lt;template&gt;  &lt;div class&#x3D;&quot;home&quot;&gt;    &lt;button @click&#x3D;&quot;test&quot;&gt;点击&lt;&#x2F;butto">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202304162033788.png">
<meta property="article:published_time" content="2023-04-15T16:00:00.000Z">
<meta property="article:modified_time" content="2024-02-15T16:04:19.050Z">
<meta property="article:author" content="深海火锅店">
<meta property="article:tag" content="vue3">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:image" content="https://gitee.com/tongstyle/blog-img/raw/master/img/202304162033788.png">
  
  
    <meta name="referrer" content="no-referrer-when-downgrade">
  
  
  <title>Vue3学习 - Hexo</title>

  <link  rel="stylesheet" href="https://lib.baomitu.com/twitter-bootstrap/4.6.1/css/bootstrap.min.css" />



  <link  rel="stylesheet" href="https://lib.baomitu.com/github-markdown-css/4.0.0/github-markdown.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/hint.css/2.7.0/hint.min.css" />

  <link  rel="stylesheet" href="https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.css" />



<!-- 主题依赖的图标库，不要自行修改 -->
<!-- Do not modify the link that theme dependent icons -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_hj8rtnfg7um.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_lbnruvf0jn.css">


<link  rel="stylesheet" href="/css/main.css" />


  <link id="highlight-css" rel="stylesheet" href="/css/highlight.css" />
  
    <link id="highlight-css-dark" rel="stylesheet" href="/css/highlight-dark.css" />
  




  <script id="fluid-configs">
    var Fluid = window.Fluid || {};
    Fluid.ctx = Object.assign({}, Fluid.ctx)
    var CONFIG = {"hostname":"example.com","root":"/","version":"1.9.3","typing":{"enable":true,"typeSpeed":70,"cursorChar":"_","loop":false,"scope":[]},"anchorjs":{"enable":true,"element":"h1,h2,h3,h4,h5,h6","placement":"left","visible":"hover","icon":""},"progressbar":{"enable":true,"height_px":3,"color":"#29d","options":{"showSpinner":false,"trickleSpeed":100}},"code_language":{"enable":true,"default":"TEXT"},"copy_btn":true,"image_caption":{"enable":true},"image_zoom":{"enable":true,"img_url_replace":["",""]},"toc":{"enable":true,"placement":"right","headingSelector":"h1,h2,h3,h4,h5,h6","collapseDepth":0},"lazyload":{"enable":true,"loading_img":"/img/loading.gif","onlypost":false,"offset_factor":2},"web_analytics":{"enable":false,"follow_dnt":true,"baidu":null,"google":null,"gtag":null,"tencent":{"sid":null,"cid":null},"woyaola":null,"cnzz":null,"leancloud":{"app_id":null,"app_key":null,"server_url":null,"path":"window.location.pathname","ignore_local":false}},"search_path":"/local-search.xml"};

    if (CONFIG.web_analytics.follow_dnt) {
      var dntVal = navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack;
      Fluid.ctx.dnt = dntVal && (dntVal.startsWith('1') || dntVal.startsWith('yes') || dntVal.startsWith('on'));
    }
  </script>
  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
  


  
<meta name="generator" content="Hexo 6.3.0"></head>


<body>
  

  <header>
    

<div class="header-inner" style="height: 70vh;">
  <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand" href="/">
      <strong>Fluid</strong>
    </a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" target="_self" href="javascript:;" data-toggle="modal" data-target="#modalSearch" aria-label="Search">
              &nbsp;<i class="iconfont icon-search"></i>&nbsp;
            </a>
          </li>
          
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" target="_self" href="javascript:;" aria-label="Color Toggle">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

  

<div id="banner" class="banner" parallax=true
     style="background: url('/img/background.jpg') no-repeat center center; background-size: cover;">
  <div class="full-bg-img">
    <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
      <div class="banner-text text-center fade-in-up">
        <div class="h2">
          
            <span id="subtitle" data-typed-text="Vue3学习"></span>
          
        </div>

        
          
  <div class="mt-3">
    
    
      <span class="post-meta">
        <i class="iconfont icon-date-fill" aria-hidden="true"></i>
        <time datetime="2023-04-16 00:00" pubdate>
          2023年4月16日 凌晨
        </time>
      </span>
    
  </div>

  <div class="mt-1">
    
      <span class="post-meta mr-2">
        <i class="iconfont icon-chart"></i>
        
          8.7k 字
        
      </span>
    

    
      <span class="post-meta mr-2">
        <i class="iconfont icon-clock-fill"></i>
        
        
        
          73 分钟
        
      </span>
    

    
    
  </div>


        
      </div>

      
    </div>
  </div>
</div>

</div>

  </header>

  <main>
    
      

<div class="container-fluid nopadding-x">
  <div class="row nomargin-x">
    <div class="side-col d-none d-lg-block col-lg-2">
      

    </div>

    <div class="col-lg-8 nopadding-x-md">
      <div class="container nopadding-x-md" id="board-ctn">
        <div id="board">
          <article class="post-content mx-auto">
            <!-- SEO header -->
            <h1 style="display: none">Vue3学习</h1>
            
            
              <div class="markdown-body">
                
                <h2 id="Vue3学习"><a href="#Vue3学习" class="headerlink" title="Vue3学习"></a>Vue3学习</h2><blockquote>
<p>要求，点击按钮，改变数据<br>vue2的写法也可以实现</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;div class=&quot;home&quot;&gt;<br>    &lt;button @click=&quot;test&quot;&gt;点击&lt;/button&gt;<br>    &lt;br&gt;<br>    &lt;span&gt;count:&#123;&#123;count&#125;&#125;&lt;/span&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script lang=&quot;ts&quot;&gt;<br>import &#123; defineComponent &#125; from &#x27;vue&#x27;;<br><br>export default defineComponent(&#123;<br>  name: &#x27;Home&#x27;,<br>  props: &#123;<br>    msg: String,<br>  &#125;,<br>  data()&#123;<br>    return&#123;<br>      count:0<br>    &#125;<br>  &#125;,<br>  methods:&#123;<br>    test()&#123;<br>      this.count++;<br>    &#125;<br>  &#125;<br>&#125;);<br>&lt;/script&gt;<br><br>&lt;style scoped&gt;<br>button&#123;<br>  width: 80px;<br>  height: 30px;<br>&#125;<br>&lt;/style&gt;<br></code></pre></td></tr></table></figure>

<blockquote>
<p>接下来看vue3的写法</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;div class=&quot;home&quot;&gt;<br>    &lt;button @click=&quot;test&quot;&gt;点击&lt;/button&gt;<br>    &lt;br&gt;<br>    &lt;span&gt;count:&#123;&#123;count&#125;&#125;&lt;/span&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script lang=&quot;ts&quot;&gt;<br>import &#123; defineComponent &#125; from &#x27;vue&#x27;;<br><br>export default defineComponent(&#123;<br>  name: &#x27;Home&#x27;,<br>  props: &#123;<br>    msg: String,<br>  &#125;,<br>  setup()&#123;<br>    // 变量<br>    let count=0;<br>    // 方法<br>    function test()&#123;<br>      count++;<br>      console.log(&quot;测试:&quot;,count);<br>    &#125;<br>    return&#123;<br>      count:count,<br>      test<br>    &#125;<br>  &#125;<br>&#125;);<br>&lt;/script&gt;<br><br>&lt;style scoped&gt;<br>button&#123;<br>  width: 80px;<br>  height: 30px;<br>&#125;<br>&lt;/style&gt;<br></code></pre></td></tr></table></figure>

<blockquote>
<p>然而此时的页面并没有变化，为什么？</p>
<p><code>因为此时的数据并不是响应式数据</code></p>
</blockquote>
<p><img src="https://gitee.com/tongstyle/blog-img/raw/master/img/202304162033788.png" srcset="/img/loading.gif" lazyload alt="image-20230416203338618"></p>
<h3 id="ref"><a href="#ref" class="headerlink" title="ref"></a>ref</h3><blockquote>
<p>正确写法<br><code>ref一般用来定义一个基本类型的响应式数据</code></p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;div class=&quot;home&quot;&gt;<br>    &lt;button @click=&quot;test&quot;&gt;点击&lt;/button&gt;<br>    &lt;br&gt;<br>    &lt;span&gt;count:&#123;&#123;count&#125;&#125;&lt;/span&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script lang=&quot;ts&quot;&gt;<br>import &#123;defineComponent, ref&#125; from &#x27;vue&#x27;;<br><br>export default defineComponent(&#123;<br>  name: &#x27;Home&#x27;,<br>  props: &#123;<br>    msg: String,<br>  &#125;,<br>  setup()&#123;<br>    // ref一般用来定义一个基本类型的响应式数据，若需要将一个对象变成响应式数据该用谁呢？（答:reactive）<br>    let count=ref(0);<br>    // 方法<br>    function test()&#123;<br>      // count是一个ref对象，所以不能直接count++<br>      // 而上面并没有写&#123;&#123;count.value&#125;&#125;来进行渲染，而是&#123;&#123;count&#125;&#125;<br>      count.value++;<br>      console.log(&quot;测试:&quot;,count);<br>    &#125;<br>    return&#123;<br>      count:count,<br>      test<br>    &#125;<br>  &#125;<br>&#125;);<br>&lt;/script&gt;<br><br>&lt;style scoped&gt;<br>button&#123;<br>  width: 80px;<br>  height: 30px;<br>&#125;<br>&lt;/style&gt;<br></code></pre></td></tr></table></figure>

<h3 id="reactive"><a href="#reactive" class="headerlink" title="reactive"></a>reactive</h3><blockquote>
<p>要求，显示用户的相关信息，点击按钮后更新用户信息</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;div class=&quot;home&quot;&gt;<br>    &lt;button @click=&quot;test&quot;&gt;点击&lt;/button&gt;<br>    &lt;br&gt;<br>    &lt;p&gt;姓名:&#123;&#123;user.name&#125;&#125;&lt;/p&gt;<br>    &lt;p&gt;年龄:&#123;&#123;user.age&#125;&#125;&lt;/p&gt;<br>    &lt;p&gt;座驾:&#123;&#123;user.cars&#125;&#125;&lt;/p&gt;<br>    &lt;ul&gt;<br>      &lt;li&gt;父亲姓名:&#123;&#123;user.father.name&#125;&#125;&lt;/li&gt;<br>      &lt;li&gt;父亲年龄:&#123;&#123;user.father.age&#125;&#125;&lt;/li&gt;<br>    &lt;/ul&gt;<br><br>    &lt;ul&gt;<br>      &lt;li&gt;母亲姓名:&#123;&#123;user.mather.name&#125;&#125;&lt;/li&gt;<br>      &lt;li&gt;母亲年龄:&#123;&#123;user.father.age&#125;&#125;&lt;/li&gt;<br>    &lt;/ul&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script lang=&quot;ts&quot;&gt;<br>import &#123;defineComponent, reactive, ref&#125; from &#x27;vue&#x27;;<br><br>export default defineComponent(&#123;<br>  name: &#x27;Home&#x27;,<br>  props: &#123;<br>    msg: String,<br>  &#125;,<br>  /*<br>  作用:定义多个数据的响应式<br>  const proxy=reactive(obj):接收一个普通对象然后返回该普通对象的响应式代理器对象<br>  响应式转换是“深层的”:会影响对象内部所有嵌套的属性<br>  内部基于ES6的Proxy实现，通过代理对象操作源对象内部数据都是响应式的<br>  */<br>  setup() &#123;<br>    // 把数据编程响应式的数据<br>    // 返回的是一个proxy代理对象，被代理的对象是传入的对象<br>    // testObj是代理对象，而obj是目标对象<br>    // obj=&#123;&#125;<br>    // const testObj=reactive(obj);<br>    // obj.name=&#x27;aaa&#x27;<br>    // 直接使用目标对象的方式来更新属性的值，是无法改变的，只能使用代理对象来进行修改<br>    // 正确使用方式如下:<br>    // testObj.name=&#x27;aaa&#x27;<br>    let user = reactive(&#123;<br>      name: &quot;王明&quot;,<br>      age: 20,<br>      cars: [&#x27;风火轮&#x27;, &#x27;哮天犬&#x27;, &#x27;筋斗云&#x27;],<br>      father: &#123;<br>        name: &quot;王海&quot;,<br>        age: 45<br>      &#125;,<br>      mather: &#123;<br>        name: &quot;李花花&quot;,<br>        age: 43<br>      &#125;<br>    &#125;);<br>    // 方法<br>    const test=()=&gt;&#123;<br>      user.name+=&#x27;-&#x27;;<br>      user.age++;<br>      user.cars=[&#x27;葫芦&#x27;,&#x27;飞剑&#x27;]<br>    &#125;<br>    return &#123;<br>      user: user,<br>      test<br>    &#125;<br>  &#125;<br>&#125;);<br>&lt;/script&gt;<br><br>&lt;style scoped&gt;<br>button &#123;<br>  width: 80px;<br>  height: 30px;<br>&#125;<br>&lt;/style&gt;<br></code></pre></td></tr></table></figure>

<blockquote>
<p>新需求，</p>
<p>user-&gt;代理对象<br>obj -&gt;目标对象</p>
<ol>
<li>user对象或者obj对象<code>添加</code>一个<code>新的属性</code>，哪种方式会影响界面的更新？</li>
<li>user对象或者obj对象<code>移除</code>一个<code>已存在的属性</code>，哪种方式会影响界面的更新？</li>
</ol>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;div class=&quot;home&quot;&gt;<br>    &lt;button @click=&quot;test&quot;&gt;点击&lt;/button&gt;<br>    &lt;br&gt;<br>    &lt;p&gt;姓名:&#123;&#123;user.name&#125;&#125;&lt;/p&gt;<br>    &lt;p&gt;年龄:&#123;&#123;user.age&#125;&#125;&lt;/p&gt;<br>    &lt;p&gt;性别:&#123;&#123;user.gender&#125;&#125;&lt;/p&gt;<br>    &lt;p&gt;座驾:&#123;&#123;user.cars&#125;&#125;&lt;/p&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script lang=&quot;ts&quot;&gt;<br>import &#123;defineComponent, reactive, ref&#125; from &#x27;vue&#x27;;<br><br>export default defineComponent(&#123;<br>  name: &#x27;Home&#x27;,<br>  props: &#123;<br>    msg: String,<br>  &#125;,<br>  setup() &#123;<br>    // 为了在使用【obj.gender=&#x27;男&#x27;;】时不出现错误信息才采用这种写法<br>    // let obj:any=&#123;<br>    let obj:any=&#123;<br>      name: &quot;王明&quot;,<br>      age: 20,<br>      cars: [&#x27;风火轮&#x27;, &#x27;哮天犬&#x27;, &#x27;筋斗云&#x27;]<br>    &#125;;<br>    let user = reactive(obj);<br>    // 方法<br>    const test=()=&gt;&#123;<br>      // 这种方式页面并没有更新渲染，但是obj中的属性已被添加<br>      // obj.gender=&#x27;男&#x27;;<br><br>      // 为了不出现错误提示，可【let obj:any=&#123;】或者【let user = reactive&lt;any&gt;(obj);】<br>      // 这种方式可以更新界面，而且属性也被添加到obj对象了<br>      user.gender=&#x27;男&#x27;<br><br>      // 界面没有更新，但是obj中的属性已被删除<br>      // delete obj.age;<br><br>      // 页面更新渲染,obj中属性已被删除<br>      delete user.age;<br>      console.log(user);<br>    &#125;<br>    return &#123;<br>      user: user,<br>      test<br>    &#125;<br>  &#125;<br>&#125;);<br>&lt;/script&gt;<br><br>&lt;style scoped&gt;<br>button &#123;<br>  width: 80px;<br>  height: 30px;<br>&#125;<br>&lt;/style&gt;<br></code></pre></td></tr></table></figure>

<blockquote>
<p><code>总结：</code>如果操作代理对象,目标对象中的数据也会随之变化，同时如果想要在操作数据的时候，界面也要跟着重新更新渲染，那么需要操作代理对象</p>
</blockquote>
<h3 id="vue2与vue3响应式的对比"><a href="#vue2与vue3响应式的对比" class="headerlink" title="vue2与vue3响应式的对比"></a>vue2与vue3响应式的对比</h3><blockquote>
<p>vue2</p>
</blockquote>
<ul>
<li><p>核心:</p>
<ul>
<li>对象:通过defineProperty对对象的已有属性值的读取和修改进行劫持(监视&#x2F;拦截)</li>
<li>数组:通过重写数组更新数组一系列更新元素的方法来实现元素修改的劫持</li>
</ul>
</li>
<li><p>问题</p>
<ul>
<li>对象直接新添加的属性或删除已有属性,界面不会自动更新</li>
<li>直接通过下标替换元素或更新length,界面不会自动更新arr[1]&#x3D; {}</li>
</ul>
</li>
</ul>
<blockquote>
<p>vue3</p>
</blockquote>
<ul>
<li>核心:<ul>
<li>通过Proxy(代理):拦截对data任意属性的任意(13种)操作,包括属性值的读写,属性的添加，属性的删除等..</li>
<li>通过Reflect(反射):动态对被代理对象的相应属性进行特定的操作</li>
</ul>
</li>
</ul>
<h3 id="响应式数据"><a href="#响应式数据" class="headerlink" title="响应式数据"></a>响应式数据</h3><blockquote>
<p>响应式数据原理:</p>
<p>直接在vue项目中新建一个html页面</p>
</blockquote>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br></pre></td><td class="code"><pre><code class="hljs html"><span class="hljs-meta">&lt;!DOCTYPE <span class="hljs-keyword">html</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">html</span> <span class="hljs-attr">lang</span>=<span class="hljs-string">&quot;en&quot;</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">head</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">meta</span> <span class="hljs-attr">charset</span>=<span class="hljs-string">&quot;UTF-8&quot;</span>&gt;</span><br>    <span class="hljs-tag">&lt;<span class="hljs-name">title</span>&gt;</span>响应式的原理<span class="hljs-tag">&lt;/<span class="hljs-name">title</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">head</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">body</span>&gt;</span><br><span class="hljs-tag">&lt;<span class="hljs-name">script</span>&gt;</span><span class="language-javascript"></span><br><span class="language-javascript">    <span class="hljs-comment">// 目标对象</span></span><br><span class="language-javascript">    <span class="hljs-keyword">const</span> user = &#123;</span><br><span class="language-javascript">        <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;佐助&#x27;</span>,</span><br><span class="language-javascript">        <span class="hljs-attr">age</span>: <span class="hljs-number">20</span>,</span><br><span class="language-javascript">        <span class="hljs-attr">wife</span>: &#123;</span><br><span class="language-javascript">            <span class="hljs-attr">name</span>: <span class="hljs-string">&#x27;小樱&#x27;</span>,</span><br><span class="language-javascript">            <span class="hljs-attr">age</span>: <span class="hljs-number">19</span></span><br><span class="language-javascript">        &#125;</span><br><span class="language-javascript">    &#125;</span><br><span class="language-javascript">    <span class="hljs-comment">// 代理对象</span></span><br><span class="language-javascript">    <span class="hljs-keyword">const</span> proxyUser = <span class="hljs-keyword">new</span> <span class="hljs-title class_">Proxy</span>(user, &#123;</span><br><span class="language-javascript">        <span class="hljs-comment">// 获取目标对象的某个属性值</span></span><br><span class="language-javascript">        <span class="hljs-title function_">get</span>(<span class="hljs-params">target, prop</span>) &#123;</span><br><span class="language-javascript">            <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&quot;get方法被调用了&quot;</span>);</span><br><span class="language-javascript">            <span class="hljs-keyword">return</span> <span class="hljs-title class_">Reflect</span>.<span class="hljs-title function_">get</span>(target, prop);</span><br><span class="language-javascript">        &#125;,</span><br><span class="language-javascript">        <span class="hljs-comment">// 修改目标对象的属性值 &amp; 为目标对象添加新的属性</span></span><br><span class="language-javascript">        <span class="hljs-title function_">set</span>(<span class="hljs-params">target, prop, newValue</span>) &#123;</span><br><span class="language-javascript">            <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&quot;set方法被调用了&quot;</span>);</span><br><span class="language-javascript">            <span class="hljs-keyword">return</span> <span class="hljs-title class_">Reflect</span>.<span class="hljs-title function_">set</span>(target, prop, newValue);</span><br><span class="language-javascript">        &#125;,</span><br><span class="language-javascript">        <span class="hljs-comment">// 删除目标对象上的某个属性</span></span><br><span class="language-javascript">        <span class="hljs-title function_">deleteProperty</span>(<span class="hljs-params">target, prop</span>) &#123;</span><br><span class="language-javascript">            <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(<span class="hljs-string">&quot;deleteProperty方法被调用了&quot;</span>);</span><br><span class="language-javascript">            <span class="hljs-keyword">return</span> <span class="hljs-title class_">Reflect</span>.<span class="hljs-title function_">deleteProperty</span>(target, prop);</span><br><span class="language-javascript">        &#125;</span><br><span class="language-javascript">    &#125;);</span><br><span class="language-javascript"></span><br><span class="language-javascript">    <span class="hljs-comment">// 通过代理对象获取目标对象的信息</span></span><br><span class="language-javascript">    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(proxyUser.<span class="hljs-property">name</span>);</span><br><span class="language-javascript">    <span class="hljs-comment">// 通过代理对象更新目标对象上的属性值</span></span><br><span class="language-javascript">    proxyUser.<span class="hljs-property">name</span> = <span class="hljs-string">&#x27;鸣人&#x27;</span>;</span><br><span class="language-javascript">    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(user);</span><br><span class="language-javascript">    <span class="hljs-comment">// 通过代理对象向目标对象中添加一个新的属性</span></span><br><span class="language-javascript">    proxyUser.<span class="hljs-property">gender</span>=<span class="hljs-string">&#x27;男&#x27;</span>;</span><br><span class="language-javascript">    <span class="hljs-comment">// 通过代理对象删除目标对象中的属性</span></span><br><span class="language-javascript">    <span class="hljs-keyword">delete</span> proxyUser.<span class="hljs-property">name</span>;</span><br><span class="language-javascript">    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(user);</span><br><span class="language-javascript">    <span class="hljs-comment">// 更新目标对象中的某个属性的对象的值</span></span><br><span class="language-javascript">    proxyUser.<span class="hljs-property">wife</span>.<span class="hljs-property">name</span>=<span class="hljs-string">&#x27;雏田&#x27;</span>;</span><br><span class="language-javascript">    <span class="hljs-variable language_">console</span>.<span class="hljs-title function_">log</span>(user);</span><br><span class="language-javascript"></span><span class="hljs-tag">&lt;/<span class="hljs-name">script</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">body</span>&gt;</span><br><span class="hljs-tag">&lt;/<span class="hljs-name">html</span>&gt;</span><br></code></pre></td></tr></table></figure>

<blockquote>
<p>响应式数据的测试</p>
</blockquote>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;div class=&quot;home&quot;&gt;<br>    &lt;button @click=&quot;test&quot;&gt;点击&lt;/button&gt;<br>    &lt;br&gt;<br>    &lt;p&gt;姓名:&#123;&#123;user.name&#125;&#125;&lt;/p&gt;<br>    &lt;p&gt;年龄:&#123;&#123;user.age&#125;&#125;&lt;/p&gt;<br>    &lt;p&gt;性别:&#123;&#123;user.gender&#125;&#125;&lt;/p&gt;<br>    &lt;p&gt;座驾:&#123;&#123;user.cars&#125;&#125;&lt;/p&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script lang=&quot;ts&quot;&gt;<br>import &#123;defineComponent, reactive, ref&#125; from &#x27;vue&#x27;;<br><br>export default defineComponent(&#123;<br>  name: &#x27;Home&#x27;,<br>  props: &#123;<br>    msg: String,<br>  &#125;,<br>  setup() &#123;<br>    // 为了在使用【obj.gender=&#x27;男&#x27;;】时不出现错误信息才采用这种写法<br>    // let obj:any=&#123;<br>    let obj:any=&#123;<br>      name: &quot;王明&quot;,<br>      age: 20,<br>      cars: [&#x27;风火轮&#x27;, &#x27;哮天犬&#x27;, &#x27;筋斗云&#x27;]<br>    &#125;;<br>    let user = reactive(obj);<br>    // 方法<br>    const test=()=&gt;&#123;<br>      user.cars[0]=&#x27;炼丹炉&#x27;;<br>      // 数组中添加新元素<br>      user.cars[3]=&#x27;葫芦&#x27;;<br>    &#125;<br>    return &#123;<br>      user: user,<br>      test<br>    &#125;<br>  &#125;<br>&#125;);<br>&lt;/script&gt;<br><br>&lt;style scoped&gt;<br>button &#123;<br>  width: 80px;<br>  height: 30px;<br>&#125;<br>&lt;/style&gt;<br></code></pre></td></tr></table></figure>

<h3 id="setup细节"><a href="#setup细节" class="headerlink" title="setup细节"></a>setup细节</h3><figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><code class="hljs vue">&lt;template&gt;<br>  &lt;div&gt;<br>    &lt;h2&gt;子级组件&lt;/h2&gt;<br>    &lt;p&gt;msg:&#123;&#123;msg&#125;&#125;&lt;/p&gt;<br>  &lt;/div&gt;<br>&lt;/template&gt;<br><br>&lt;script lang=&quot;ts&quot;&gt;<br>import &#123;defineComponent&#125; from &#x27;vue&#x27;;<br><br>export default defineComponent(&#123;<br>  name: &#x27;Child&#x27;,<br>  props:[&#x27;msg&#x27;],<br>  // setup细节问题:<br>  // 1.setup在beforeCreate之前就会执行<br>  setup()&#123;<br>    console.log(&quot;setup执行了&quot;);<br>    // setup中一般都是返回一个对象，对象中的属性和方法可以都在html模板中使用<br>    return&#123;<br><br>    &#125;<br>  &#125;,<br>  // 数据初始化的生命周期的回调<br>  beforeCreate() &#123;<br>    console.log(&quot;beforeCreate执行了&quot;);<br>  &#125;<br>&#125;);<br>&lt;/script&gt;<br><br>&lt;style scoped&gt;<br>&lt;/style&gt;<br></code></pre></td></tr></table></figure>


                
              </div>
            
            <hr/>
            <div>
              <div class="post-metas my-3">
  
    <div class="post-meta mr-3 d-flex align-items-center">
      <i class="iconfont icon-category"></i>
      

<span class="category-chains">
  
  
    
      <span class="category-chain">
        
  <a href="/categories/vue3/" class="category-chain-item">vue3</a>
  
  

      </span>
    
  
</span>

    </div>
  
  
    <div class="post-meta">
      <i class="iconfont icon-tags"></i>
      
        <a href="/tags/vue3/">#vue3</a>
      
    </div>
  
</div>


              
  

  <div class="license-box my-3">
    <div class="license-title">
      <div>Vue3学习</div>
      <div>http://example.com/2023/04/16/编程语言/Vue/Vue3/Vue3学习/</div>
    </div>
    <div class="license-meta">
      
        <div class="license-meta-item">
          <div>作者</div>
          <div>深海火锅店</div>
        </div>
      
      
        <div class="license-meta-item license-meta-date">
          <div>发布于</div>
          <div>2023年4月16日</div>
        </div>
      
      
      
        <div class="license-meta-item">
          <div>许可协议</div>
          <div>
            
              
              
                <a target="_blank" href="https://creativecommons.org/licenses/by/4.0/">
                  <span class="hint--top hint--rounded" aria-label="BY - 署名">
                    <i class="iconfont icon-by"></i>
                  </span>
                </a>
              
            
          </div>
        </div>
      
    </div>
    <div class="license-icon iconfont"></div>
  </div>



              
                <div class="post-prevnext my-3">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2023/04/19/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/Js&amp;JQuery/JavaScript&amp;JQuery%E5%A4%8D%E4%B9%A0/" title="JavaScript&amp;JQuery复习">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">JavaScript&amp;JQuery复习</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2023/04/16/%E7%BC%96%E7%A8%8B%E8%AF%AD%E8%A8%80/Vue/%E5%B8%83%E5%B1%80/Flex%E5%B8%83%E5%B1%80/" title="flex布局">
                        <span class="hidden-mobile">flex布局</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>

    <div class="side-col d-none d-lg-block col-lg-2">
      
  <aside class="sidebar" style="margin-left: -1rem">
    <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div class="toc-body" id="toc-body"></div>
</div>



  </aside>


    </div>
  </div>
</div>





  



  



  



  



  







    

    
      <a id="scroll-top-button" aria-label="TOP" href="#" role="button">
        <i class="iconfont icon-arrowup" aria-hidden="true"></i>
      </a>
    

    
      <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v" for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>

    

    
  </main>

  <footer>
    <div class="footer-inner">
  
    <div class="footer-content">
       <a href="https://hexo.io" target="_blank" rel="nofollow noopener"><span>Hexo</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
    </div>
  
  
    <div class="statistics">
  
  

  
    
      <span id="busuanzi_container_site_pv" style="display: none">
        总访问量 
        <span id="busuanzi_value_site_pv"></span>
         次
      </span>
    
    
      <span id="busuanzi_container_site_uv" style="display: none">
        总访客数 
        <span id="busuanzi_value_site_uv"></span>
         人
      </span>
    
    
  
</div>

  
  
  
</div>

  </footer>

  <!-- Scripts -->
  
  <script  src="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.js" ></script>
  <link  rel="stylesheet" href="https://lib.baomitu.com/nprogress/0.2.0/nprogress.min.css" />

  <script>
    NProgress.configure({"showSpinner":false,"trickleSpeed":100})
    NProgress.start()
    window.addEventListener('load', function() {
      NProgress.done();
    })
  </script>


<script  src="https://lib.baomitu.com/jquery/3.6.0/jquery.min.js" ></script>
<script  src="https://lib.baomitu.com/twitter-bootstrap/4.6.1/js/bootstrap.min.js" ></script>
<script  src="/js/events.js" ></script>
<script  src="/js/plugins.js" ></script>


  <script  src="https://lib.baomitu.com/typed.js/2.0.12/typed.min.js" ></script>
  <script>
    (function (window, document) {
      var typing = Fluid.plugins.typing;
      var subtitle = document.getElementById('subtitle');
      if (!subtitle || !typing) {
        return;
      }
      var text = subtitle.getAttribute('data-typed-text');
      
        typing(text);
      
    })(window, document);
  </script>




  
    <script  src="/js/img-lazyload.js" ></script>
  




  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/tocbot/4.18.2/tocbot.min.js', function() {
    var toc = jQuery('#toc');
    if (toc.length === 0 || !window.tocbot) { return; }
    var boardCtn = jQuery('#board-ctn');
    var boardTop = boardCtn.offset().top;

    window.tocbot.init(Object.assign({
      tocSelector     : '#toc-body',
      contentSelector : '.markdown-body',
      linkClass       : 'tocbot-link',
      activeLinkClass : 'tocbot-active-link',
      listClass       : 'tocbot-list',
      isCollapsedClass: 'tocbot-is-collapsed',
      collapsibleClass: 'tocbot-is-collapsible',
      scrollSmooth    : true,
      includeTitleTags: true,
      headingsOffset  : -boardTop,
    }, CONFIG.toc));
    if (toc.find('.toc-list-item').length > 0) {
      toc.css('visibility', 'visible');
    }

    Fluid.events.registerRefreshCallback(function() {
      if ('tocbot' in window) {
        tocbot.refresh();
        var toc = jQuery('#toc');
        if (toc.length === 0 || !tocbot) {
          return;
        }
        if (toc.find('.toc-list-item').length > 0) {
          toc.css('visibility', 'visible');
        }
      }
    });
  });
</script>


  <script src=https://lib.baomitu.com/clipboard.js/2.0.11/clipboard.min.js></script>

  <script>Fluid.plugins.codeWidget();</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/anchor-js/4.3.1/anchor.min.js', function() {
    window.anchors.options = {
      placement: CONFIG.anchorjs.placement,
      visible  : CONFIG.anchorjs.visible
    };
    if (CONFIG.anchorjs.icon) {
      window.anchors.options.icon = CONFIG.anchorjs.icon;
    }
    var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
    var res = [];
    for (var item of el) {
      res.push('.markdown-body > ' + item.trim());
    }
    if (CONFIG.anchorjs.placement === 'left') {
      window.anchors.options.class = 'anchorjs-link-left';
    }
    window.anchors.add(res.join(', '));

    Fluid.events.registerRefreshCallback(function() {
      if ('anchors' in window) {
        anchors.removeAll();
        var el = (CONFIG.anchorjs.element || 'h1,h2,h3,h4,h5,h6').split(',');
        var res = [];
        for (var item of el) {
          res.push('.markdown-body > ' + item.trim());
        }
        if (CONFIG.anchorjs.placement === 'left') {
          anchors.options.class = 'anchorjs-link-left';
        }
        anchors.add(res.join(', '));
      }
    });
  });
</script>


  
<script>
  Fluid.utils.createScript('https://lib.baomitu.com/fancybox/3.5.7/jquery.fancybox.min.js', function() {
    Fluid.plugins.fancyBox();
  });
</script>


  <script>Fluid.plugins.imageCaption();</script>

  <script  src="/js/local-search.js" ></script>

  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>




  
<script src="//cdn.jsdelivr.net/gh/EmoryHuang/BlogBeautify@1.1/DynamicRibbon.min.js"></script>



<!-- 主题的启动项，将它保持在最底部 -->
<!-- the boot of the theme, keep it at the bottom -->
<script  src="/js/boot.js" ></script>


  

  <noscript>
    <div class="noscript-warning">博客在允许 JavaScript 运行的环境下浏览效果更佳</div>
  </noscript>
</body>
</html>
